#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
int graph[201][201];
int book[201][201];//book[i][j]=1 代表地图上graph[i][j]已经访问过
int n, m;//地图大小 n行m列


int fx[4][2] = {{0,  1},
                {1,  0},
                {0,  -1},
                {-1, 0}};
int area = 0;//当前区域的面积
int max_area = 0;//最大区域面积
int islands = 0;//区域个数

void dfs(int x, int y) {
    // cout << graph[x][y];
    ++area;
    book[x][y] = 1;
    for (int i = 0; i < 4; i++) {
        int dx = fx[i][0];
        int dy = fx[i][1];
        int nx = x + dx;
        int ny = y + dy;
        if (nx < 0 || nx >= n || ny < 0 || ny >= m || book[nx][ny] == 1 || graph[nx][ny] == 0)continue;
        dfs(nx, ny);

    }

}

int main() {
    //freopen("J.in", "r", stdin);
    int T;
    cin >> T;
    while (T--) {
        cin >> n >> m;
        memset(book, 0, sizeof(book));
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                cin >> graph[i][j];
            }
        }
        max_area = 0;
        islands = 0;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++) {
                if (graph[i][j] == 1 && book[i][j] == 0) {
                    ++islands;
                    area = 0;
                    dfs(i, j);
                    if (area > max_area) {
                        max_area = area;
                    }
                }
            }
        cout << max_area << endl;//最大岛屿
        cout << "islands=" << islands << endl;//岛屿个数

    }
    return 0;
}